﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Kooboo.IoC;
using System.Web;
using Kooboo.Commerce.Contexts.ShopSettings;

namespace Kooboo.Commerce
{
    public static class BrandCommand
    {
        public static void Exclude(this IBrand brand, IProductType productType)
        {
            using (var context = ContextContainer.Current.Resolve<Kooboo.Domain.TransactionContext>())
            {
                var respository = ContextContainer.Current.Resolve<IBrandRepository>();
                respository.Exclude(brand, productType);

                context.Commit();
            }
        }

        public static void Include(this IBrand brand, IProductType productType)
        {
            using (var context = ContextContainer.Current.Resolve<Kooboo.Domain.TransactionContext>())
            {
                var respository = ContextContainer.Current.Resolve<IBrandRepository>();
                respository.Include(brand, productType);

                context.Commit();
            }
        }

        public static string BuildLogoUrl(this IBrand brand)
        {
            if (!String.IsNullOrEmpty(brand.Logo))
            {
                return Configuration.AppRootPath.Replace("\\", "/") + Configuration.ImageFolderName + "/" + Configuration.BrandLogoFolder + "/" + HttpUtility.UrlEncode(brand.Logo);
            }
            else
            {
                return "/images/no-image.png";
            }
        }

        public static string BuildThubmailLogoUrl(this IBrand brand)
        {
            if (!String.IsNullOrEmpty(brand.Logo))
            {
                var host = new ServiceHost();
                return Configuration.AppRootPath.Replace("\\", "/") + Configuration.ImageFolderName + "/" + Configuration.BrandLogoFolder + "/" + host.GetShopSettings().ImageSettings.Thumbnail.Name + "/" + HttpUtility.UrlEncode(brand.Logo);
            }
            else
            {
                return "/images/no-image.png";
            }
        }
    }
}
